package com.lc.tgxm.conn;

import com.lc.tgxm.model.User;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONObject;

/**
 * 注册接口
 * Created by Lei on 2016/6/12.
 */
@HttpInlet(Conn.URL_REG)
public class RegAsyPost extends BaseAsyPost<User> {
    public String phone;
    public String user_pass;
    public String code;

    public RegAsyPost(AsyCallBack<User> asyCallBack) {
        super(asyCallBack);
    }

    @Override
    protected User successParser(JSONObject object) {
        User user = new User();
        JSONObject jsonObject = object.optJSONObject("data");
        user.uid = jsonObject.optString("user_id");
        return user;
    }

    @Override
    protected User failParser(JSONObject object) {
        int code = object.optInt("code");
        // 根据code,处理不同的失败状态码，给TOAST赋予不同的提示语
        switch (code) {
            case 401:
                TOAST = "用户名已经存在";
                break;
            case 403:
                TOAST = "手机号不合法";
                break;
            case 500:
                TOAST = "服务器异常";
                break;
        }
        return null;
    }
}